package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.Images;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.view.ImageManager;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by MrPu on 15/12/17.
 */
public class ImageAdapter extends BaseAdapter {
    private Context context;
    private List<Images> images;

    public ImageAdapter(Context context, List<Images> images) {
        this.context = context;
        this.images = images;
    }

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHodler hodler;
        if (view == null){
            hodler = new ViewHodler();
            view = LayoutInflater.from(context).inflate(R.layout.item_imges ,null);
            hodler.Img(view);
            view.setTag(hodler);
        }else {
            hodler = (ViewHodler) view.getTag();
        }
        ImageManager.loadImage(UrlConstant.BASE_URL + images.get(position).getImagePath(), hodler.iv_img);
        return view;
    }

    class ViewHodler{
        @InjectView(R.id.iv_img)
        ImageView iv_img;
        public void Img(View view){
            ButterKnife.inject(this ,view);
        }
    }
}
